package com.hong.qrpc.strategy.register;

import com.hong.config.constant.ClientConfig;
import com.hong.qrpc.RpcClient;
import com.hong.qrpc.listener.impl.NacosServerListListener;
import com.hong.qrpc.register.nacos.NacosRegister;
import com.hong.qrpc.strategy.PropertiesStrategy;
import com.hong.qrpc.utils.StringUtils;

//import com.hong.qrpc.listener.impl.Registrar;

/**
 * @Author HQT
 * @Date 2022/7/23 20:21
 */
public class RegisterTypeStrategy implements PropertiesStrategy {
    @Override
    public void disposeProperties(RpcClient rpcClient) {
        String registerCenterType = (String) rpcClient.getConfigManager().getProfile()
                .get(ClientConfig.QRPC_REGISTER_CENTER_TYPE);
        if (!StringUtils.isEmpty(registerCenterType)) {
            switch (registerCenterType.toLowerCase()) {
                case "nacos":
                    rpcClient.setRegister(new NacosRegister());
                    rpcClient.getConfigManager().getRegisterConfig().setServerListListenerClass(NacosServerListListener.class);
                    return;
                default:
                    throw new IllegalArgumentException("unsupported properties:qrpc.register.center.type = " + registerCenterType);
            }
        }
    }
}
